home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / indeo / nwxmas / xd_play.c < prev    next >
C/C++ Source or Header  |  1993-12-05  |  2KB  |  100 lines

  1. /*
  2. **    ╔══════════════════════════════════════════════════════════════╗
  3. **    ║                                                              ║
  4. **    ║     Copyright (c) 1993 Digital Video Arts, Ltd.              ║
  5. **    ║                    All Rights Reserved                       ║
  6. **    ║                                                              ║
  7. **    ╚══════════════════════════════════════════════════════════════╝
  8. **
  9. **    Christmas card demo
  10. **
  11. **    file: xd_video.c - loop the avss file
  12. */
  13. #include <stdio.h>
  14. #include <fcntl.h>
  15. #include "nw.h"
  16. #include "nwau.h"
  17. #include "nwerrno.h"
  18. #include "xmasdemo.h"
  19. /* 
  20. **    Ths AvDispatch array is used to tell NewWorld which hook routines
  21. **    are being provided by the programmer.  In this case only one is 
  22. **    provided, graphics().  It is to be called after the iamge has 
  23. **    been decompressed
  24. */
  25. static AvDispatchArray da = {
  26.     sizeof(AvDispatchArray),
  27.     P_Y,                /* graphics only on Y plane */
  28.     0,                /* not interested in data in */
  29.     0,                /* for audio, video, or */
  30.     0,                /* underlay */
  31.     0,                /* don't care about before */
  32.     AvGraphics            /* just after decompression */
  33. };
  34.  
  35. PlayVideo()
  36. {
  37.     AvDispatch(a, &da);
  38.     AvBind(a);
  39.     AvRead(a, 0L);
  40.  
  41. /*
  42. **    If  the input has reached the end, seek to beginning and
  43. **    start again (only once per turn)
  44. */
  45.     if(a->in_frame >= a->framecnt-1) {
  46.         AvLSeek(a, 0L, SEEK_SET);
  47.         AvRead(a, a->framecnt);
  48.     }
  49.     return 0;
  50. }
  51.  
  52. PlayAudio()
  53. {
  54.     static int initialized = 0;
  55.     static int playcount = 0;
  56.     static long orglength;
  57.     static vobj v;
  58.     static int running;
  59.     static AudBlock loc;
  60.  
  61.     if(playcount > 2) return 0;
  62.  
  63.     if(!initialized) {
  64.         running = 0;
  65.         v.addr = AUDIOBUFFER;
  66.         v.size = FRAME_SIZE;
  67.         orglength = audiolength;
  68.         initialized = 1;
  69.     }
  70.  
  71.     if(audiolength > 0) {
  72.  
  73.         if ((AudChAlloc(channel,  &v)) == 0) 
  74.             return 0;
  75.  
  76.         if((AudChWrite(channel, &v, &loc)) > 0) 
  77.             AudChPlay(&loc);
  78.         else
  79.             return 0;
  80.     
  81.         if(!running) {
  82.             AudChRun(channel);
  83.             running = 1;
  84.         }
  85.  
  86.         v.addr += v.size;
  87.         audiolength -= v.size;
  88.         if(audiolength < v.size) v.size = audiolength;
  89.     }
  90.  
  91.     if(audiolength == 0 && AudChDone(channel)){
  92.         audiolength = orglength;
  93.         v.addr = AUDIOBUFFER;
  94.         v.size = FRAME_SIZE;
  95.         ++playcount;
  96.     }
  97.     return 0;
  98.  
  99. }
  100.